<?php
    /*
    *   Template name: Поломнические поездки
    *   Template post type: page
    */
    
global $post;
$mypages = get_posts( array(
    'posts_per_page' => 6,
    'post_type'   => 'travel',
) );

get_header();

?>  
<section class="content">
    <h1><?php the_title(); ?> </h1>
    <div class="product">
        <?php
        if($mypages){
         foreach($mypages as $post ){
            setup_postdata( $post );
            $photo = carbon_get_post_meta( $post->ID , 'photo');
            $img = wp_get_attachment_image_url( $photo , 'large');
            $trips = carbon_get_post_meta( $post->ID , 'trips');
            ?>
                <div class="product<?php the_ID()?> ">
                    <div class="card">
                        <div class="card__img">
                            <a href="<?php the_permalink(); ?>">
                                <img src="<?php echo $img?>" alt="<?php the_title(); ?>">
                            </a>
                        </div>
                        <div class="card_date">
                            <?php 
                            if($trips){
                                foreach($trips as $trip):
                                    ?>
                                <div class="card_date_day">
                                    <p><?php echo $trip['number_days_trip'];echo "&nbsp;" . number_word($trip['number_days_trip']);?></p>
                                        <?php
                                            foreach($trip['data_time_trips'] as $date):
                                            $date_departure_trips = new DateTime($date['data_departure_trips']);
                                        ?>
                                     <button class="open_form" type="button" dataDeys="<?php echo $trip['number_days_trip'] ?>" dataDate="<?php echo $date_departure_trips->format('d.m.Y');?>" dataTitle="<?php the_title(); ?>" dataLinck="<?php the_permalink(); ?>"><?php echo $date_departure_trips->format('d.m.Y');?><br>Заказать</button>
                                        <?php endforeach;?><!--//конец foreach -->
                                </div>
                                    
                                <?php endforeach;?><!--//конец foreach -->
                            </div>
                            <div class="card__data">
                                <h4 class="card__header">
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                </h4>

                                <div>
                                    <?php foreach($trips as $trip):?>
                                    <div class="card__prise">
                                        <p><?php echo $trip['number_days_trip'];echo "&nbsp;" . number_word($trip['number_days_trip']) . "&nbsp;" . ":" ;?></p>
                                        <a href="<?php the_permalink(); ?>">
                                            <span>
                                                <?php echo $trip['price_place'];?>&#x20bd
                                            </span>
                                        </a>
                                    </div>  
                                    <?php endforeach;?> <!--//конец foreach -->
                                </div>
                            </div>
                            <?php }?>  <!--//конец if -->
                    </div>  
                </div>
        <?php }}// Конец foreach if
wp_reset_postdata();
?>
  </div>
 </section>
<?php
    get_footer();
